<?php
function addNews(){
    global $form,$ctrl,$database,$user;
    define("REQ_LEVEL",9);
    if($user->level < REQ_LEVEL) return UN_AUTH;
    $str;

    if(isset($_SESSION['addNewsItem'])){
        unset($_SESSION['addNewsItem']);
        $str.= "<div class='notice'>Data Entered Successfully !!</div>";
        //$str.="Data Entered Successfully !!";
    }

    if(isset($_POST['add'])){

        //print_r($_POST);
        //die();
        $retval = $ctrl->addNews($_POST);

        if($retval){
            $_SESSION['addNewsItem'] = true;
            header("Location:".$ctrl->referrer);				
        }
        else{
            $_SESSION['value_array'] = $_POST;
            $_SESSION['error_array'] = $form->getErrorArray();
            header("Location:".$ctrl->referrer);				
        }
    } else {
        Page::$jslink=array('js/ui.core.js','js/ui.datepicker.js');
        Page::$csslink=array('css/ui.all.css');
        $title = $database->getTitle();

        $str .="<div id ='heading'><h3>Add News </h3></div>
            <div><form method='POST' action='{$_SERVER['REQUEST_URI']}'>
            <div>Date : <input type='text' name='entered_date' id='datepicker' value=\"{$form->value('entered_date')}\" />{$form->error('entered_date')}</div>
            <div>Title : <input type='text' name='title' size=40 value=\"{$form->value('title')}\" />{$form->error('title')}</div>";

        $str .="<div>Body : <textarea rows='4' cols='40' name='body'>{$form->value('body')}</textarea>{$form->error('body')}</div>
            <div><input type='hidden' name='add'></div>
            <div><input type='submit' value='Add' name='submit'></div>
            </form></div>
            <script type='text/javascript'>
$(document).ready(function(){
    $('#datepicker').datepicker({dateFormat:'yy-mm-dd'});
    });
                </script>";

            return $str;
}
}
?>
